package com.beike.entity;

import com.baomidou.mybatisplus.annotation.EnumValue;

public enum UserStatus {
    ACTIVE("active"),
    DISABLED("disabled");

    @EnumValue  // 标记数据库存储的值
    private final String value;

    UserStatus(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public static UserStatus fromValue(String value) {
        if (value == null) {
            throw new IllegalArgumentException("Status value cannot be null");
        }
        
        // First try to match the enum name directly
        try {
            return UserStatus.valueOf(value.toUpperCase());
        } catch (IllegalArgumentException ignored) {
            // If that fails, try to match the string value
            for (UserStatus status : UserStatus.values()) {
                if (status.value.equalsIgnoreCase(value)) {
                    return status;
                }
            }
            throw new IllegalArgumentException("Invalid UserStatus value: " + value);
        }
    }
} 